<?php

require_once("models/ISearchable.php");

class nameSearch implements ISearchable{
	
    private $m_name ;
    private $m_param ;
    
	const ENDS = 4 ;
    const BEGINS = 3 ;
    const CONTAINS = 2 ;
    const NOT_EQUAL = 1 ;
    const EQUAL = 0 ;
    
    
    public function __construct($a_name, $a_param) {
        $this->m_name = strtolower($a_name) ;
        $this->m_param = $a_param ;
    }

	public function isSelected(MemberClass $a_member) {
        $memberName = strtolower($a_member->name);
        switch($this->m_param) {
            case self::EQUAL :
                if ($memberName == $this->m_name) {
                    return TRUE ;
                }
                break ;
            case self::NOT_EQUAL :
                if ($memberName != $this->m_name) {
                    return TRUE ;
                }
                break ;
            case self::CONTAINS :
                if (strpos($memberName, $this->m_name) !== FALSE) {
                    return TRUE ;
                }
                break ;
            case self::BEGINS :
				if (substr($memberName, 0, strlen($this->m_name)) == $this->m_name) {
                    return TRUE ;
                }
                break ;
            case self::ENDS :
				if (substr($memberName, -strlen($this->m_name)) == $this->m_name) {
                    return TRUE ;
                }
                break ;
        }
        return FALSE ;

	}
}
